﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _002银行ATM模拟
{
    /// <summary>
    /// 银行账户
    /// </summary>
    class BankAccount
    {
        //定义常量
        public const string LESSBALANCE = "账户余额不足";
        public const string ILLEGALMONEY = "金额不合法";
        private string _name;//姓名
        private string _accountID;//银行账号
        private float _balance;//余额
        private string _message;//返回信息
        
        //只读属性
        public string Name
        {
            //只能返回字段值
            get { return _name; }        
        }
        public string AccountID
        {
            //只能返回字段值
            get { return _accountID; }
        }
        public string Message
        {
            get { return _message; }
        }

        //可读可写属性
        public float Balance
        {
            get { return _balance; }
            set
            {
                //50的倍数
                if (value > 0)
                    _balance = value;               
            }
        }

        /// <summary>
        /// 无参数的默认实例构造函数
        /// </summary>
        public BankAccount():this("中国","ChinaBank0001",500)
        {
            Console.WriteLine("无参的构造函数被调用");
           
        }
        /// <summary>
        /// 带参数的构造函数
        /// </summary>
        /// <param name="name">账户名</param>
        /// <param name="accountID">账户ID</param>
        /// <param name="balance">账户余额</param>
        public BankAccount(string name,string accountID,float balance)
        {
            _name = name;
            _accountID = accountID;
            _balance = balance;
            //Console.WriteLine("有三个参数的构造函数被调用");
        }

        //存款
        public bool Deposit(int money)
        {
            if(money % 50 == 0)
            {
                Balance += money;
                return true;
            }
            
            return false;
        }

        //取款
        public bool WithDraw(int money)
        {
            
            if (money < _balance && money % 50 == 0)
            {
                _balance -= money;
                return true;
            }
            if (money > _balance) _message = LESSBALANCE;//余额不足
            if (money % 50 != 0) _message = ILLEGALMONEY;//不合法金额
            return false;
        }

        //打印账户信息
        public void PrintAccountInfo()
        {
            Console.WriteLine("---------账户信息--------");
            Console.WriteLine("账户名:{0}",_name);
            Console.WriteLine("账户ID:{0}",_accountID);
            Console.WriteLine("账户余额:{0}",_balance);
            Console.WriteLine("-------------------------");
        }
    }
}
